package com.example.newnoke.ui;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.view.View;

import com.example.newnoke.R;
import com.example.newnoke.data.BaseDatas;
import com.example.newnoke.data.UserData;
import com.example.newnoke.databinding.ActivityInfoBinding;
import com.example.newnoke.mvp.presenter.UserPresenter;
import com.example.newnoke.mvp.view.IUserV;
import com.example.newnoke.utils.API;
import com.geya.jbase.baseactivity.BaseDetailsActivity;
import com.geya.jbase.constant.RequestType;
import com.geya.jbase.uiview.ToastUtil;

import java.util.HashMap;

public class InfoActivity extends BaseDetailsActivity<UserPresenter> implements IUserV {

    private ActivityInfoBinding mBinding;

    @Override
    public UserPresenter newPresenter() {
        return new UserPresenter(this);
    }

    @Override
    public void init() {

        mTitleButton.setTitles("个人信息");
        mTitleButton.setRButtonText("保存");
        mTitleButton.setRButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HashMap<String, String> map = new HashMap<>();
                  map.put("name", mBinding.name.getText().toString());
                  map.put("alipay", mBinding.zbf.getText().toString());
                mPresenter.accessServers(RequestType.OKGO_POST, API.UPDATA, BaseDatas.class, map);
            }
        });
        HashMap<String, String> map = new HashMap<>();
        mPresenter.accessServers(RequestType.OKGO_POST, API.USER, UserData.class, map);
    }

    @Override
    public void setContentView() {
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_info);
    }

    @Override
    public void setData(UserData.DataBean data) {
        mBinding.name.setText(data.getName());
        mBinding.shouji1.setText(data.getMobile());
//        mBinding.shouji2.setText(data.getFmobile());
        mBinding.zbf.setText(data.getAlipay_account());
        mBinding.name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBinding.name.setText("");
            }
        });

            mBinding.zbf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mBinding.zbf.setText("");
                }
            });

        mBinding.mima.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             startActivity(new Intent(InfoActivity.this,MiMaActivity.class));
            }
        });
    }

    @Override
    public void showMsg(int code, String msg) {
        ToastUtil.showShort(msg);
        if (code == 200) {
            finish();
        }
    }
}
